#ifndef _USILIB_H_
#define _USILIB_H_

#define USI_NO_ERR		0

#define USI_TIMEOUT		-1	/* device time-out */
#define USI_ERR_COUNT	-2	/* device transfer count error */
#define USI_ERR_BITLEN	-3	/* device bit length error */
#define USI_ERR_DEVICE	-4	/* device id error */
#define SPI_ERASE_ADDR_ERROR	-5	/* erase address should 64KB boundary */

#define SPI_SET_CLOCK	0

/* extern function */
VOID spiIoctl(INT32 spiFeature, INT32 spicArg0);
INT  spiOpen(VOID);
INT  spiRead(INT32 spiReadAddress, INT32 spiLength, INT32 spiTargetAddr);
INT  spiWrite(INT32 spiWriteAddress, INT32 spiLength, INT32 spiSourceAddr);


/* internal function */
int usiActive(void);
int usiTxLen(int count, int bitLen);
int usiCheckBusy(void);
int usiRead(UINT32 addr, UINT32 sectorCount, UINT8 *buf);
int usiReadFast(UINT32 addr, UINT32 len, UINT8 *buf);
int usiWriteEnable(void);
int usiWriteDisable(void);
int usiWrite(UINT32 addr, UINT32 len, UINT16 *buf);
int usiEraseSector(UINT32 addr, UINT32 secCount);
int usiEraseAll(void);
UINT16 usiReadID(void);
UINT8 usiStatusRead(void);
int usiStatusWrite(UINT8 data);

int  usiInitDevice(void);
VOID usiSetClock(INT32 clock_by_MHz);


#endif
